package com.itheima.info.manage.system.dao;

import com.itheima.info.manage.system.domain.Teacher;

import java.util.ArrayList;

public class TeacherDao {
    //封装 老师数据
   private static ArrayList<Teacher> list= new ArrayList<>();

    //增
    public void addTeacher(Teacher teacher){
        list.add(teacher);
    }

    //删
    public void deleteTeacherBySid(String sid){
       //根据学号删除集合中指定的老师
        int index = getIndex(sid);
        list.remove(index);
    }

    //改
    public void updateTeacher(String sid,Teacher newTeacher){
        int index = getIndex(sid);
        list.set(index,newTeacher);
    }

    //查
    public ArrayList<Teacher> findAllTeachers(){
        return list;
    }

    //根据条件查
    public int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if(teacher.getSid().equals(sid)){
                return i;
            }
        }
         return -1;
    }
}
